package com.welink.cmp.meatdata.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.welink.cmp.convertor.GenericConvertor;
import com.welink.cmp.dao.metadata.dataobject.DataCenterDO;
import com.welink.cmp.dto.metadata.datacenter.*;
import com.welink.cmp.meatdata.command.DataCenterCmdExe;
import com.welink.common.dto.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataCenterAppService {

    @Autowired
    private DataCenterCmdExe dataCenterCmdExe;

    /**
     * 添加机房
     *
     * @param addCmd 添加机房的命令对象
     * @return 新增机房的ID
     */
    public Long addDataCenter(DatacenterAddCmd addCmd) {
        return dataCenterCmdExe.save(addCmd);
    }

    /**
     * 更新机房
     *
     * @param updCmd 更新机房的命令对象
     * @return 更新是否成功
     */
    public Boolean updateDataCenter(DatacenterUpdCmd updCmd) {
        return dataCenterCmdExe.update(updCmd);
    }

    /**
     * 根据ID获取机房
     *
     * @param id 机房ID
     * @return 机房业务对象
     */
    public DataCenterCO getDataCenterById(Long id) {
        return dataCenterCmdExe.queryById(id);
    }

    /**
     * 分页查询机房
     *
     * @param pageQry 分页查询条件
     * @return 分页响应，包括机房列表和分页信息
     */
    public PageResponse<DataCenterCO> dataCenterPageQuery(DatacenterPageQry pageQry) {
        final Page<DataCenterDO> pageR = dataCenterCmdExe.pageQuery(pageQry);
        final List<DataCenterDO> records = pageR.getRecords();
        List<DataCenterCO> coList = GenericConvertor.toCOList(records, DataCenterCO.class);
        return PageResponse.of(coList,pageR.getTotal(),pageR.getSize(),pageR.getCurrent());
    }
}
